<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Pre中的代码</title>
<style type="text/css">
pre.sourceCode {
	background-color: #9FB5DE;
	border: 1px solid black;
	margin-left: 2em;
}

pre.sourceCode ol {
	padding: 0;
	margin: 0;
	margin-left: 35px;
}

pre.sourceCode li {
	padding: 2px 10px;
	border-left: 2px groove silver;
	color: #333;
}

pre.sourceCode li.odd {
	background-color: #dbdbdb;
}

pre.sourceCode li.even {
	background-color: #d4d4d4;
}

pre.sourceCode li:hover {
	background-color: #9FB5DE;
}
</style>
<script type="text/javascript">
    window.onload = function() {
        var preElements = document.getElementsByTagName("pre");

        for (var i = 0; i < preElements.length; i++) {
            var target = preElements.item(i);
            if (target.className != "sourceCode") {
                continue;
            }

            var content = target.firstChild.nodeValue;
            var linesArray = content.split(String.fromCharCode(13));
            if (linesArray.length == 1) {
                linesArray = content.split(String.fromCharCode(10));
            }

            var olContainer = document.createElement("ol");
            var index = 1;
            for (var j = 0; j < linesArray.length; j++) {
                var liContainer = document.createElement("li");
                liContainer.className = index++ % 2 ? "odd" : "even";

                var spanContainer = document.createElement("span");
                var aText = document.createTextNode(linesArray[j]);
                
                spanContainer.appendChild(aText);
                liContainer.appendChild(spanContainer);
                olContainer.appendChild(liContainer);
            }

            while (target.firstChild) {
                target.removeChild(target.firstChild);
            }

            target.appendChild(olContainer);
        }
    }
</script>

</head>
<body>
<pre class="sourceCode">
#include &lt;iostream&gt;
int main(){
	std::cout &lt;&lt; "Hello world";
	return 0;
}</pre>
</body>
</html>